package com.example.demo.controller;

import com.example.demo.base.baseController;
import com.example.demo.entity.Comment;
import com.example.demo.service.CommentService;
import com.example.demo.vo.Result;
import com.example.demo.vo.ResultCode;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import jakarta.annotation.Resource;
import lombok.NonNull;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 三石
 */
@RestController
@RequestMapping("/comment")
public class CommentController extends baseController<CommentService, Comment> {
    @Resource
    private CommentService commentService;

    @Operation(summary = "添加评价")
    @PostMapping("/addComment")
    public Result addComment(@Parameter(name = "userId", description = "用户id", required = true) @NonNull Long userId,
                             @Parameter(name = "goodsId", description = "商品id", required = true) @NonNull Long goodsId,
                             @Parameter(name = "commentText", description = "评价内容", required = true) @NonNull String commentText,
                             @Parameter(name = "orderId", description = "订单id", required = true) @NonNull Long orderId,
                             @Parameter(name = "plusComment", description = "是否追加评价", required = true)  Integer plusComment){
        // 调用service
        commentService.addComment(userId, goodsId, commentText,orderId,plusComment);
        // 返回
        return Result.ok(ResultCode.SUCCESS);
    }


    @Operation(summary = "根据商品id获取评价对象")
    @GetMapping("/getCommonByGoodsId")
    public List<Comment> getCommonByGoodsId(@Parameter(name = "goodsId", description = "商品id", required = true) @NonNull Long goodsId) {
        // 调用service
        List<Comment> comment = commentService.getCommonByGoodsId(goodsId);
        // 返回
        return comment;
    }


}
